﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using WindowsPhone.PushNotificationManager;
using System.Collections.Generic;
using DevCorner.Services.Interfaces;

namespace DevCorner.Services
{
  [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  public class NotificationService : INotificationService
  {
    INotificationClient client;

    #region INotificationService Members

    public void SendRAWNotification(List<Uri> Uris, byte[] payload)
    {
      client = OperationContext.Current.GetCallbackChannel<INotificationClient>();

      NotificationSenderUtility.SendRawNotification(Uris, payload, SendNotificationToMPNSCompleted);
    }

    public void SendToastNotification(List<Uri> Uris, string message1, string message2)
    {
      client = OperationContext.Current.GetCallbackChannel<INotificationClient>();

      NotificationSenderUtility.SendToastNotification(Uris, message1, message2, SendNotificationToMPNSCompleted);
    }

    public void SendTileNotification(List<Uri> Uris, string TokenID, string BackgroundImageUri, int Count, string Title)
    {
      client = OperationContext.Current.GetCallbackChannel<INotificationClient>();

      NotificationSenderUtility.SendTileNotification(Uris, TokenID, BackgroundImageUri, Count, Title, SendNotificationToMPNSCompleted);
    }

    private void SendNotificationToMPNSCompleted(CallbackArgs response)
    {
      client.NotifyOnMessageSend(response);
    }

    #endregion
  }
}
